package com.wkq.move.module.tv.ui.adapter

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wkq.lib_base.adapter.KtDataBindingViewHolder
import com.wkq.move.R
import com.wkq.move.databinding.ItemTvSiteBinding
import com.wkq.net.model.UsTvDetailInfo

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/5/20
 *
 * 用途:
 */


class TvSiteAdapter(context: Context, layoutId: Int) :
    KtDataBindingAdapter<UsTvDetailInfo.PlayOnLineBean>(context, layoutId) {

    var listener : OnItemClickListener ? =null

    fun setOnItemClickListener(listener : OnItemClickListener){
        this.listener=listener
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        var ktDataBindingViewHolder = holder as KtDataBindingViewHolder
        var itemTvSiteBinding = ktDataBindingViewHolder.getBinding() as ItemTvSiteBinding
        itemTvSiteBinding.data = getItem(position)

        var siteInfoAdapter = SiteInfoAdapter(mContext, R.layout.item_site_info)
        itemTvSiteBinding.rvContent.layoutManager = LinearLayoutManager(mContext)
        itemTvSiteBinding.rvContent.adapter = siteInfoAdapter
        siteInfoAdapter.addItems(getItem(position)?.playOnLineInfoList)
        if (listener != null) {

            siteInfoAdapter.setOnViewClickListener(object :OnAdapterViewClickListener<UsTvDetailInfo.PlayOnLineInfo>{
                override fun onViewClick(v: View?, program: UsTvDetailInfo.PlayOnLineInfo?) {
                    listener?.onItemClick(program)
                }

            })

        }



    }

    interface  OnItemClickListener{
        fun onItemClick (program: UsTvDetailInfo.PlayOnLineInfo?)
    }



}

